const crypto = require("crypto")
//key密钥
const cacheAK = require('../util/const').cacheAK
//aes128加密
const encrypt = (data, key) => {
  let t1 = crypto.createCipheriv('aes-128-cbc', cacheAK, cacheAK)
  let crypted = t1.update(data, 'utf-8', 'hex')
  crypted += t1.final('hex')
  return crypted
}


//aes128解密
const decrypt = (crypted, key) => {
  let t2 = crypto.createDecipheriv('aes-128-cbc', cacheAK, cacheAK)
  let decrypted = t2.update(crypted, 'hex', 'utf8')
  decrypted += t2.final('utf8')
  return decrypted
}


// console.log(unaes256encrypt(aes256encrypt("123456",cacheAK),cacheAK));

module.exports = { encrypt, decrypt }